home *** CD-ROM | disk | FTP | other *** search
- class Snd extends Sound
- {
- var target;
- var manager;
- var _volume;
- var onFadeComplete;
- var fId;
- static var FADE_RATE = 100;
- function Snd(targ, sndman)
- {
- super(targ);
- this.target = !targ ? _root : targ;
- this.manager = sndman;
- this._volume = super.getVolume();
- }
- function switchSound(id, loops)
- {
- var _loc3_ = this.position;
- super.stop();
- super.attachSound(id);
- this.start(_loc3_ % this.duration / 1000,loops);
- }
- function fade(dVol, tVol, handler)
- {
- this.onFadeComplete = handler;
- if(this.fId)
- {
- this.stopFade(this.fId);
- }
- this.fId = setInterval(this,"changeVolTowards",Snd.FADE_RATE,dVol * (Snd.FADE_RATE / 1000),tVol,true);
- }
- function fadeBy(dVol, t, handler)
- {
- this.onFadeComplete = handler;
- if(this.fId)
- {
- this.stopFade(this.fId);
- }
- if(t > 0)
- {
- this.fId = setInterval(this,"changeVolTowards",Snd.FADE_RATE,dVol * (Snd.FADE_RATE / 1000),dVol * t,true);
- }
- }
- function fadeTo(tVol, t, handler)
- {
- this.onFadeComplete = handler;
- if(this.fId)
- {
- this.stopFade(this.fId);
- }
- if(t > 0)
- {
- var _loc3_ = (tVol - this.getVolume()) / t;
- this.fId = setInterval(this,"changeVolTowards",Snd.FADE_RATE,_loc3_ * (Snd.FADE_RATE / 1000),tVol,true);
- }
- else
- {
- this.setVolume(tVol);
- }
- }
- function changeVolTowards(dVol, tVol, fading)
- {
- var _loc2_ = this.getVolume();
- if(Math.abs(dVol) < Math.abs(tVol - _loc2_))
- {
- this.changeVolume(dVol);
- }
- else
- {
- this.setVolume(tVol);
- if(fading)
- {
- this.stopFade();
- }
- }
- }
- function stopFade()
- {
- if(this.fId)
- {
- clearInterval(this.fId);
- delete this.fId;
- this.onFadeComplete();
- delete this.onFadeComplete;
- }
- }
- function positionSound(a, d, f, t)
- {
- if(d < f)
- {
- t = !isNaN(t) ? (t >= 0 ? t : 0) : 100;
- d = d >= 1 ? d : 1;
- var _loc4_ = 1 / (d / f * 100);
- this.setVolume(Math.ceil(_loc4_ * t));
- this.setPan((- Math.sin(a)) * 100);
- }
- else
- {
- this.setVolume(0);
- }
- }
- function positionSoundLinear(a, d, f, t)
- {
- if(d < f)
- {
- t = !isNaN(t) ? (t >= 0 ? t : 0) : 100;
- this.setVolume((f - d) / f * t);
- this.setPan((- Math.sin(a)) * 100);
- }
- else
- {
- this.setVolume(0);
- }
- }
- function setVolume(n)
- {
- this._volume = n;
- super.setVolume(n);
- }
- function getVolume()
- {
- return this._volume;
- }
- function changeVolume(n)
- {
- this.setVolume(this.getVolume() + n);
- }
- function remove()
- {
- super.stop();
- delete this.manager.sounds[this.target.getDepth()];
- this.target.removeMovieClip();
- false;
- }
- function toString()
- {
- return "(target=" + this.target + ")";
- }
- function get volume()
- {
- return this._volume;
- }
- function set volume(n)
- {
- this._volume = n;
- super.setVolume(n);
- }
- }
-